<?php


    /**
    * @author NU SIT Bar
    * @version 1.0
    * @created 20.Jul.2012 8:43:39 h
    */
    class Folders extends MX_Controller
    {

        private $data;

        function __construct()
        {

            parent::__construct();
            $this->load->model('document_model');
            $this->load->model('pages_model');
            $this->load->config('documents');
            $this->load->library('translate', array('lang' => $this->session->userdata('my_language')));

        }

        public function index($params)
        { 
            //print_r($params['link']);
            $this->data['link'] = $params['link'];
            if(!isset($_GET['post_type']))
            {
                $_GET['post_type']="page";
            }   
            $this->view_all();
        }

        /**
        * 
        * @param post_type              
        * @param type
        */
        function view_all()
        {
            $this->data['title'] = "Documents";
            $this->data['post_type'] = $_GET['post_type'];

            //$this->firephp->log($_GET['type']);

            if($_GET['type']=='all')
            {  
                echo $this->load->view('view_all_all', $this->data, TRUE);    
            }
            else
            {
                $this->data['all_folders'] = $this->document_model->view_all($_GET['type']);   
                echo $this->load->view('view_all', $this->data, TRUE);  
            }


        }

        /**
        * 
        * @param post_type
        * @param type
        */
        function add_folder_files($params)
        {
            $this->data['link'] = $params['link'];
            $this->data['title'] = "New Folder / files";
            $this->data['post_type'] = $_GET['post_type'];
            //$this->data['all_galleries'] = $this->document_model->view_all(NULL);
            echo $this->load->view('add_folder_files', $this->data, TRUE);
        }

        /**
        * 
        * @param gallery_ID
        * @param post_type
        */
        function view_edit($params)
        {
            $this->data['link'] = $params['link'];
            $this->data['title'] = "Edit document";
            $this->data['post_type'] = $_GET['post_type'];
            $this->data['gallery'] = $this->document_model->view_edit($_GET['gallery_ID']);
            $this->data['images'] = $this->document_model->view_edit_files($_GET['gallery_ID']);
            //$this->data['videos'] = $this->document_model->view_edit_videos($_GET['gallery_ID']);
            echo $this->load->view('edit_folder', $this->data, TRUE);
        }

        /**
        * 
        * @param post_action
        * @param type
        * @param galleryname
        * @param parent_id
        */
        function add_document()
        {     
            $result = $this->document_model->add_document(
                $_POST['type'], 
                $_POST['galleryname'], 
                $_POST['parent_id']
            );

            if($result)$message = 'Successful add folder operation.';

            return $result.'-'.$message;
        }

        /**
        * 
        * @param post_action
        * @param galleryselect  91<--delimiter!-->gall91-gal1 ( gallery_ID <--delimiter!--> path )
        * @param pictures => array
        * @param pic_titles => array
        */
        function add_files()
        {
            //load reasize library
            $this->load->library('img_map');

            $result = $this->document_model->add_files(
                $_POST['galleryselect'], 
                $_POST['pictures'], 
                $_POST['pic_titles']
            );

            if($result)$message = 'Successful add files operation.';

            return $result.'-'.$message;    
        }

        /**
        * 
        * @param post_action
        * @param gallery_ID
        * @param linkto
        * @param galleryname
        * @param parent_id
        */
        function edit_document()
        {
            $result = $this->document_model->edit_document(
                $_POST['gallery_ID'], 
                $_POST['galleryname'], 
                $_POST['linkto'], 
                $_POST['parent_id']
            );

            if($result)$message = 'Successful edit document operation.';

            return $result.'-'.$message;
        }

        /**
        * 
        * @param gallery_ID
        */
        function delete($params)
        {
            $result = $this->document_model->delete($params['gallery_ID']);

            if($result)$message = 'Successful delete document operation.';

            return $result.'-'.$message;
        }

        /**
        * 
        * @param picture_ID
        * @param gallery_ID
        */
        function delete_file()
        {
            $result = $this->document_model->delete_file($_GET['picture_ID'], $_GET['gallery_ID']); 

            if($result)$message = 'Successful delete file operation.';

            return $result.'-'.$message;
        }
        
         /**
        * 
        * @param gallery_ID
        * @param picture-order => array
        */
        function files_order()
        {
            $result = $this->document_model->files_order($_POST['gallery_ID'], $_POST['picture-order']); 

            if($result)$message = 'Successful picture order operation.';

            return $result.'-'.$message;
        }


    }
?>